package cn.edu.zust.companyservice.controller;

import Company.Dto.Company;
import cn.edu.zust.companyservice.mapper.CompanyMapper;
import cn.edu.zust.companyservice.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;
    @Autowired
    private CompanyMapper companyMapper;

    @GetMapping("/getAudited")
    public List<Company> getAuditedCompany() {
        return companyMapper.getAuditedCompany();
    }
    @GetMapping("/findCompany/{id}")
    public Company getCompanyById(@PathVariable int id) {
        return companyMapper.findCompanyById(id);
    }

    @PostMapping("/register")
    public ResponseEntity<?> registerCompany(@RequestBody Company company) {
        try {
            companyService.deliverCompany(company);
            return new ResponseEntity<>("公司注册成功", HttpStatus.OK);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseEntity<>("公司注册失败，请稍后再试", HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
    @GetMapping("/getAllCompany")
    public List<Company> getAllCompany() {
        return companyService.getAllCompany();
    }

    @GetMapping("/auditCompany")
    public List<Company> auditCompany() {
        return companyMapper.auditCompany();
    }

    @GetMapping("/{id}/{status}")
    public void shiftStatus(@PathVariable("id") int id, @PathVariable("status")int status) {
        companyMapper.shiftStatus(id, status);
    }

    @GetMapping("/sentAccountAndPassword/{id}/{account}/{password}")
    public void sentAccountAndPassword(@PathVariable("id") int id, @PathVariable("account") String account, @PathVariable("password") String password) {
        companyMapper.sentAccountAndPassword(id, account, password);
    }

    @GetMapping("/login/{account}")
    public String getPasswordByAccount(@PathVariable("account") String account) {
        return companyService.getPasswordByAccount(account);
    }

}
